﻿using Spire.Doc;
using System;
using System.IO;
using System.Windows.Forms;

namespace WordTool
{
    public partial class Form1 : Form
    {
        FolderBrowserDialog ofd = new FolderBrowserDialog();
        string path = string.Empty;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ofd.ShowDialog();
            path = ofd.SelectedPath.ToString();
            this.listBox1.Items.Add(path);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            path = string.Empty;
            this.listBox1.Items.Clear();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DirectoryInfo folder = new DirectoryInfo(path);
            foreach (FileInfo file in folder.GetFiles("*.doc"))
            {
                Document doc = new Spire.Doc.Document();
                doc.LoadFromFile(file.FullName.ToString());
                int a = doc.PageCount;
                //获取第一个section
                Spire.Doc.Section section = doc.Sections[0];
                //删除页眉 
                section.HeadersFooters.Header.ChildObjects.Clear();
                doc.SaveToFile(file.FullName.ToString(), FileFormat.Doc);
            }
            MessageBox.Show("删除眉脚成功！");
        }

    }
}